import { isNullOrEmpty } from '../is';

export function rotationPieFormat(dataSets) {
  const { dimensions, type, source } = dataSets;
  let result = [];
  const nameKey = type === 'STATIC' ? 'name' : dimensions?.xAxis;
  const valueKey = type === 'STATIC' ? 'value' : dimensions?.yAxis;
  source.forEach((dataItem) => {
    // 饼图负值和空值不显示
    if (!isNullOrEmpty(dataItem[valueKey]) && dataItem[valueKey] >=0) {
      result.push({
        name: !isNullOrEmpty(dataItem[nameKey]) ? dataItem[nameKey] : '',
        value: dataItem[valueKey],
      });
    }
  });
  return {
    seriesData: result
  };
}
